﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<script type="text/javascript">

    //统计tree上选中的人员，将其组成一个字符串数组存放在 id=selectarr 隐藏标签中
    function onUsertreeCheck_WF(event, treeId, treeNode) {
        //alert(treeNode.id + ", " + treeNode.name + "," + treeNode.checked);
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        var nodes = treeObj.getCheckedNodes(true);
        var temp = "";
        for (i = 0; i < nodes.length; i++) {
            temp = temp + nodes[i].id + ",";
        }
        $("#selectarr").attr("value", temp);
    };

    var complete = false;
    function getTable(btnTag) {
        var hidValue;
        var txtValue = "";
        complete = true;

        var tableTag = $(btnTag).parent();
        var childTag = $(tableTag).children();

        childTag.each(function() {
            var cls = $(this).attr("class");
            if (cls == "txtTable txtunderline") {
                var txt = $(this).val();
                var name = $(this).attr("name");
                if (txt == "")
                    complete = false;
                txtValue += txt + ";";
            }
            else if (cls == "hidTable")
                hidValue = $(this).val();
        });

        if (!complete) {
            alert("必须填写完整条件");
            return;
        }
        alert(txtValue);
        $.ajax({
            type: "POST",
            url: "/Form/QueryTable",
            data: { "txtValue": txtValue, "sqlValue": hidValue },
            success: function(data) {
                if (data == "none") {
                    alert("无所需查询结果");
                    complete = false;
                } else {
                    complete = true;
                    $("#updateTable").html(data);
                }
            }
        });
    };

    function OnSubmit() {

        var flag, msg;
        var table = document.getElementById("updateTable");
        var tableId = $(table).attr("id");
        if (tableId == 'updateTable') {
            if (!complete) {
                var count = $(".txtTable").length;
                if (count == 0)
                    flag = true;
                else
                    flag = false;
            } else {
                flag = true;
            }
        } else {
            flag = true;
        }

        if ($("#wf_name").val() == "") {
            flag = false;
            msg = "请填写流程名";
        }
        //mlh + 2012-04-25
        if ($("#selectarr").val() == "") {
            flag = false;
            msg = "请选择处理人";
        }
        var txtBox = $(".txtInput");
        txtBox.each(function() {
            if ($(this).val() == "") {
                flag = false;
                msg = "表单存在未填写项";
            }
        });

        if (!flag)
            alert(msg);
        else {
            var table = prodTable();
            $('#sqlargs').val(table);
        }
        return flag;
    }

    // 遍历table获得每个单元格的值
    function prodTable() {
        var tableDiv = $("#updateTable");
        var tbody = $(tableDiv).children().children();
        var trs = $(tbody).children('tr');
        var trCount = trs.length;
        var rows = "";
        var row;
        trs.each(function() {
            row = '';
            $(this).children().each(function() {
                var hidTag = $(this).children('.tbvalget');
                var hidcls = $(hidTag).attr('class');
                if (hidcls != "undefined" && hidcls != "" && hidcls != null && hidcls != "null")
                    row += $(hidTag).val() + ',';

            });
            rows += row + ';';
        })
        return rows;
    }
</script>

<div id="planstart">
    <%using (Ajax.BeginForm("DoPlanStart", "Plan", new AjaxOptions { UpdateTargetId = "workarea" }))
      { %>
    <input type="submit" value="完成并发送" onclick="return OnSubmit()" />
    <br />
    流程命名：<%=Html.TextBox("wf_name")%><br />
    <%=Html.Hidden("form_id", ViewData["form_id"])%>
    <%=Html.Hidden("wftemplate_id", ViewData["wftemplate_id"])%>
    <%=Html.Hidden("wf_id", ViewData["wf_id"])%>
    <%=Html.Hidden("selectarr", ViewData["clrs"])%>
    <%=Html.Hidden("treedefi", ViewData["treedefi"])%>
    <%=Html.Hidden("treevis", ViewData["treevisible"])%>
    <%=Html.Hidden("sqlargs")%>
    <div id="bd" style="float: left; width: 76%">
        <div id="div_bd" style="position: relative; width: 100%; height: 750px; border: solid 1px;
            overflow: auto">
            <% Response.Write(ViewData["formdefi"]); %>
        </div>
    </div>
    <div id="div_tree" class="zTreeDemoBackground left" style="float: left; width: 20%;
        margin-left: 5px;">
        <ul id="treeDemo" class="ztree" style="margin-top: 0px;">
        </ul>
    </div>
    <%} %>
</div>
